package paws.launch 

import paws.core._
import NodeType._

object Main {
  val defaultParams = {
    val np = new NodeParameters
    np.serviceRate = 100
    np.serviceVariance = 10
    np.sleepThreshold = 500
    np
  }
  
  def main(args: Array[String]) {
    val sim = new Simulation
    val nodes = 
      generateNodes( 0, 10, sim, Source) ++
      generateNodes(10, 10, sim, Destination) ++
      generateNodes(20, 90, sim, Intermediary)
    
    nodes.foreach(sim.addNode(_))
    sim.start
    
    while(sim.isRunning)
      Thread.`yield`
      
    val dataSet = sim.getData
    for(d <- dataSet) {
      println( "t="   + d.timestamp + 
               "; p=" + d.power +
               "; r=" + d.reliability +
               "; d=" + d.delay)
    }
  }
  
  def generateNodes
    (base: Int, count: Int, parent: Simulation, 
     ntype: NodeType.Value): Seq[Node] = {
    import scala.util.Random._
    
    val nodes = new Array[Node](count)
    for (j <- base until (base + count)) {
      val x, y = nextInt(10000) / 100.0
      val i = j - base
      nodes(i) = new Node(parent, defaultParams)
      nodes(i).setLocation(x, y)
      nodes(i).setID(j)
      nodes(i).setNodeType(ntype)
    }
    nodes
  }
}